#region Summary 

// 
// Owner : JackieHan 
// 
// Solution : LearnSolution
// 
// Project :JackieHan.Hibernate2.0.Test
// 
// File : TestCustomer.cs
// 
// CopyRight : Copyright © 2009-2010 JackieHan Personal, All Rights Reserved 
// 
// Summary : 测试客户信息操作
// 
// History : 
//			2010-08-18 00:48:54	    Create 
// 

#endregion

#region Using 

using System;
using System.Collections.Generic;
using JackieHan.Hibernate2.Data;
using JackieHan.Hibernate2.Domain.Entities;
using NUnit.Framework;

#endregion

namespace JackieHan.Hibernate2._0.Test
{
    /// <summary> 
    /// 测试客户信息操作
    /// </summary> 
    [TestFixture]
    public class TestCustomer
    {
        private CustomerDal customerManager;

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            customerManager = new CustomerDal();
        }

        [Test]
        public void GetCustomerByIdTest()
        {
            var tempCustomer = new CustomerInfo {FirstName = "Jackie", LastName = "Han"};
            customerManager.CreateCustomer(tempCustomer);
            tempCustomer = new CustomerInfo {FirstName = "FangWei", LastName = "Su"};
            customerManager.CreateCustomer(tempCustomer);
            CustomerInfo customer = customerManager.GetCustomerById(1);
            Assert.AreEqual(1, customer.Id);
        }

        [Test]
        public void TestForm()
        {
            IList<CustomerInfo> customerInfos = customerManager.From();
            Assert.AreEqual(customerInfos.Count, 3);
        }

        [Test]
        public void TestFromAlias()
        {
            IList<CustomerInfo> customers = customerManager.FromAlias();
            Assert.AreEqual(customers.Count, 3);
        }

        [Test]
        public void TestSelect()
        {
            IList<int> ids = customerManager.Select();
            Assert.AreEqual(ids.Count, 3);
            Assert.AreEqual(ids[0], 1);
        }

        [Test]
        public void TestSelectObject()
        {
            IList<object[]> objectses = customerManager.SelectObject();
            Assert.AreEqual(objectses.Count, 2);
            Assert.AreEqual(objectses[1][0].ToString(), "Jackie");
            Assert.AreEqual(objectses[0][0].ToString(), "FangWei");
        }

        [Test]
        public void TestAggregateFunction()
        {
            IList<object[]> objectses = customerManager.AggregateFunction();
            Assert.AreEqual(objectses.Count, 1);
            Assert.AreEqual(objectses[0][0].ToString(), "2");
            Assert.AreEqual(objectses[0][1].ToString(), "6");
            Assert.AreEqual(objectses[0][2].ToString(), "3");
        }

        [Test]
        public void TestDistinct()
        {
            IList<string> firstNames = customerManager.Distinct();
            Assert.AreEqual(firstNames.Count, 2);
        }

        [Test]
        public void TestWhere()
        {
            IList<CustomerInfo> customerInfos = customerManager.Where();
            Assert.AreEqual(customerInfos.Count, 2);
        }

        [Test]
        public void TestCreateCriteria()
        {
            IList<CustomerInfo> customerInfos = customerManager.CreateCriteria();
            Assert.AreEqual(customerInfos.Count, 3);
        }

        [Test]
        public void TestNarrowing()
        {
            IList<CustomerInfo> customerInfos = customerManager.Narrowing();
            Assert.AreEqual(customerInfos.Count, 2);
        }

        [Test]
        public void TestOrder()
        {
            IList<CustomerInfo> customerInfos = customerManager.Order();
            Assert.AreEqual(customerInfos.Count, 2);
        }
    }
}